package longcaisuyun.longcai.com.yiliubabalongcaisuyun;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;

import com.zcx.helper.http.AsyCallBack;

import java.util.ArrayList;
import java.util.List;

import longcaisuyun.longcai.com.net.GetCaoZuo;
import longcaisuyun.longcai.com.suyunbean.CaoZuoBean;



/**
 * 操作手册页面
 */

public class CaoZuoActivity extends Activity implements View.OnClickListener {

    LinearLayout fanhui_lin;
    ListView listView2;
    List<CaoZuoBean> l = new ArrayList();

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cao_zuo);
        View view = getWindow().getDecorView();
        // 适配工具将视图重新排布
        MyApplication.ScaleScreenHelper.loadView((ViewGroup) view);
        ViewInit();
        DataInit();

    }

    private void DataInit() {
        MyApplication.myviewutil.startProgressDialog(CaoZuoActivity.this);

        new GetCaoZuo(new AsyCallBack<GetCaoZuo.Info>() {
            public void onSuccess(String toast, int type, GetCaoZuo.Info info) throws Exception {
                super.onSuccess(toast, type, info);
                if (info.message.equals("1")) {
                    for (int j = 0; j < info.list.size(); j++) {
                        l.add(info.list.get(j));
                    }
                    CaoZuoAdapter c = new CaoZuoAdapter(CaoZuoActivity.this, l);
                    listView2.setAdapter(c);
                } else {
                    Toast.makeText(CaoZuoActivity.this, "获取数据失败", Toast.LENGTH_SHORT).show();
                }
                MyApplication.myviewutil.stopProgressDialog();
            }

            public void onFail(String toast, int type) throws Exception {
                super.onFail(toast, type);
                MyApplication.myviewutil.stopProgressDialog();
            }
        }).execute(CaoZuoActivity.this);
        //点击跳转操作手册
        listView2.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(CaoZuoActivity.this, CaoZuo_Inner.class);
                intent.putExtra("itemcaozuoid", l.get(position).getId());
                intent.putExtra("itemtitle",l.get(position).getTitle());
                startActivity(intent);
            }
        });

    }

    private void ViewInit() {
        fanhui_lin = (LinearLayout) findViewById(R.id.fanhui_lin);
        fanhui_lin.setOnClickListener(this);
        listView2 = (ListView) findViewById(R.id.listView2);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.fanhui_lin:
                CaoZuoActivity.this.finish();
                break;
        }
    }
}
